home *** CD-ROM | disk | FTP | other *** search
/ Sampler of Digital Rock Core Information / Sampler of Digital Rock Core Information Open File Report 91-355.ISO / source / vimage3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-06  |  53.3 KB  |  2,578 lines

  1. /* vimage3.c 11/09/89 */
  2.  
  3. /* ***** include ***** */
  4.  
  5. #include <io.h>
  6. #include <fcntl.h> 
  7. #include <sys\types.h> 
  8. #include <sys\stat.h> 
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <process.h>
  12. #include <string.h>
  13. #include <conio.h>
  14. #include <errno.h>
  15. #include <string.h>
  16. #include <dos.h>
  17. #include "getfile3.c"
  18. #include <math.h>
  19.  
  20. /* ***** define ***** */
  21. #define DEG_RAD 0.01745329251                /* converts degrees to radians */
  22. #define BANK_SEL  0xC0000400L        /* Address of bank select register */
  23. #define DISP_BUFF 0xA0000000L        /* Base address of display buffer */
  24. #define VIDIOBUFF 0xA0000000L        /* Base address of display buffer */
  25. #define ROWSIZE  640
  26. #define NWORDS   0x8000                /* Number of words in bank */
  27. #define NUMSYM 7
  28. #define MAX_DIR 20
  29. #define MAX_FIL 20
  30. #define MAX_LIST 300
  31.  
  32.  
  33. /* ***** variables ***** */
  34.  
  35.     /* ***** internal ***** */
  36.  
  37.     int List_Fil_Read=0;
  38.  
  39.     /* ***** external ***** */
  40.  
  41.     extern int ScreenXs,ScreenYs;
  42.  
  43. /* ***** arrays ***** */
  44.  
  45.     /* ***** internal ***** */
  46.  
  47.     unsigned char Vimage_Buffer[16384];
  48.     unsigned char Vi_Inbuff1[BUFSIZ],Vi_Inbuff2[BUFSIZ],Vi_Outbuff[BUFSIZ];
  49.     char Dir[MAX_DIR][30],Fil[MAX_FIL][20];
  50.     /* ***** external ***** */
  51.  
  52. /* ***** stuctures ***** */
  53.  
  54.     /* ***** definitions ***** */
  55.  
  56.     /* ***** declarations ***** */
  57.  
  58.     FILE *Vimage_Save1,*Vimage_Save2;
  59.     struct symbol
  60.     {
  61.         int scale,num;
  62.         int side[15][2];
  63.     }sym[NUMSYM]=
  64.     {
  65.         {1,8, -1,-1,  1,-1,  1, 1, -1, 1, -1,-1, -1, 1,  1, 1,  1,-1, -1,-1},
  66.         {1,4,  0,-1,  1, 0,  0, 1, -1, 0,  0,-1},
  67.         {1,3,  0,-1,  1, 1, -1, 1,  0,-1},
  68.         {2,8, -1,-2,  1,-2,  2,-1,  2, 1,  1, 2, -1, 2, -2, 1, -2,-1, -1,-2},
  69.         {3,12, -1,-1, -1,-3,  1,-3,  1,-1,  3,-1,  3, 1,  1, 1,
  70.                   1, 3, -1, 3, -1, 1, -3, 1, -3,-1, -1,-1},
  71.         {2,12,  0,-1,  1,-2,  2,-1,  1, 0,  2, 1,  1, 2,  0, 1,
  72.                  -1, 2, -2, 1, -1, 0, -2,-1, -1,-2,  0,-1},
  73.         {1,3,  0, 1,  1,-1, -1,-1,  0, 1}
  74.     };
  75.  
  76.     struct line_draw
  77.     {
  78.         int num;
  79.         char pat[16];
  80.     }line[NUMSYM]=
  81.     {
  82.         { 2,  1,0 },
  83.         { 4,  1,1,0,0},
  84.         { 6,  1,1,1,1,0,0},
  85.         { 8,  1,1,1,1,1,0,0,0},
  86.         {10,  1,1,1,1,0,0,1,1,0,0},
  87.         {12,  1,1,1,1,1,1,0,0,1,1,0,0},
  88.         {16,  1,1,1,1,1,1,0,0,1,1,0,0,1,1,0,0}
  89.     };
  90.  
  91. /* ***** functions ***** */
  92.  
  93.     /* ***** external ***** */
  94.  
  95.     /* ***** internal ***** */
  96.  
  97. void                 box(int,int,int,int,int,int);        /* draws a box */
  98. void                 cursor(int,int,int,int,int);    /* plots a cursor */
  99. void                 decode_font(int [128][25]);        /* reads 'font.hex' */
  100. int                 do_menu(char *[],int,int,int,int,int,int,int,int [128][25]); 
  101. int                 file_r(char *);     /* opens a file to read from */
  102. int                 file_w(char *);     /* opens a file to write to */
  103. int                 fillin(int,int,int,int,int,int);
  104. char                 get_ans(unsigned char *,char *,char *,int,int,int,int,int,int,
  105.                         int[128][25],int);
  106. char                 getpad(int *,int *,int *,int *,int);
  107. int                 get_fil(int,int,int,char *);
  108. unsigned char     getpt(int,int,int);            /* returns the value of a pixel */
  109. void                 getrow(int,unsigned int,unsigned int,unsigned int,
  110.                         unsigned char far *);
  111. int                 get_string(char *,unsigned char *,char *,char *,
  112.                         int,int,int,int,int,int,int [128][25],int);
  113. void                 help(int);
  114. int                 limit_area(int *,int *,int *,int *,int *,int,int,
  115.                         unsigned char *);
  116. int                 limit_area_all(int *,int *,int *,int *,int *,
  117.                         int,int,int,unsigned char *,int,int,int);
  118. int                 list_dir(char *,char *);
  119. void                 list_error(int);
  120. void                 move_image();
  121. int                 paint(int,int);
  122. void                 paint_box(int,int,unsigned char *,int,int,int,int);
  123. void                 paintcol(int,unsigned int,unsigned int,unsigned int,int);
  124. void                 pix_val(int,int);
  125. void                 plot_font_h(int,int,int,char *,int,int [128][25]);    
  126. void                 plot_font_v(int,int,int,char *,int,int [128][25]);
  127. int                  plotln(int,int,int,int,int,int);
  128. int                 plotpt(int,int,int,int);        /* plots the value of a pixel */
  129. int                 plotrow(int,int,int,int,unsigned char *);
  130. int                 plotsym( int , int , int , int , int , int );
  131. int                 read_fil(int *,int *, int *);
  132. void                 recall_sub(int,int,int,int,FILE *);
  133. void                 save_box(int,int,unsigned char *,int,int,int,int);
  134. void                 save_sub(int,int,int,int,FILE *);
  135. void                 set_files(void);
  136. void                 tbox(int,int,int,int,int,unsigned char *);
  137. int                 tbox_val(int,int,int,int,int,
  138.                         unsigned char *,int,int,int);
  139. int                 tcursor(int,int,int,int,unsigned char *);
  140. int                 t_do_menu(char [][2][50],int,int,int,int,int,
  141.                         int,int,int [128][25],int *); 
  142. int                 tplotln_inv_dot(int,int,int,int,int,
  143.                         unsigned char *,int);
  144. int                 tplotln_val(int,int,int,int,int,unsigned char *,int);
  145. void                 unbox(int,int,int,int,int,unsigned char *);
  146. void                 uncursor(int,int,int,int,unsigned char *);
  147. int                 unplotln(int,int,int,int,int,unsigned char *);
  148. void                 unsave_box(int,int,unsigned char *,int,int,int,int);
  149.  
  150.  
  151. /********************************************************************
  152. **
  153. **
  154. **
  155. ********************************************************************* */
  156.  
  157. void list_error(val)
  158.  
  159. int val;
  160.  
  161. {
  162.     if(val==-4)
  163.         printf("\n\nNo such file in directory!\n\n");
  164.     if(val==-5)
  165.         printf("\n\nDirectory contains more than %d such files!\n\n",
  166.             MAX_LIST);
  167.     if(val==-3)
  168.         printf("\n\nYou chose a file number outside the range!\n\n");
  169.  
  170. }
  171.  
  172.  
  173.  
  174. #ifdef TESTER
  175. /********************************************************************
  176. **
  177. **
  178. **
  179. ********************************************************************* */
  180.  
  181. int get_fil(num_dir,num_fil,num,string)
  182.  
  183. int num_dir,num_fil,num;
  184. char *string;
  185.  
  186. {
  187.     int i,n,d,f;
  188.     char str_dir[30],str_fil[20];
  189.     int other=0;
  190.  
  191.     if(List_Fil_Read==0)
  192.         read_fil(string);
  193.     printf("----------------------------------(data from file 'list.fil')\n");
  194.     printf("Directory                File\n\n");
  195.     for(i=0;i<num;i++)
  196.     {
  197.         if(i<num_dir)
  198.         {
  199.             printf("%c--%s",'a'+i,Dir[i]);
  200.             for(n=0;n<(22-strlen(Dir[i]));n++)
  201.                 printf(" ");
  202.         }
  203.         else
  204.             printf("                         ");
  205.         if(i<num_fil)
  206.             printf("%c -- %s\n",'a'+i,Fil[i]);
  207.         else
  208.             printf("\n");
  209.     }
  210.     printf("x -- other               x -- other\n");
  211.     printf("\ngive directory\n ");
  212.     d=getch()-'a';
  213.     if(d=='x'-'a')
  214.     {
  215.         printf("\n\nGive full directory and file type.\n");
  216.         scanf("%s",string);
  217.         return(1);
  218.     }
  219.     if(d>=0&&d<num_dir)
  220.     {
  221.         printf("%c               and File  ",d+'a');
  222.         f=getch()-'a';
  223.         if(f=='x'-'a')
  224.         {
  225.             printf("\n\nGive full directory and file type.\n");
  226.             scanf("%s",string);
  227.             return(1);
  228.         }
  229.         if(f>=0&&f<num_fil)
  230.         {
  231.             printf("%c\n",f+'a');
  232.             strcpy(string,Dir[d]);
  233.             strcpy(str_fil,Fil[f]);
  234.             strcat(string,Fil[f]);
  235.             return(1);
  236.         }
  237.         else
  238.         {
  239.             printf("\n\nLetter out of range!\n\n");
  240.             return(-1);
  241.         }
  242.     }
  243.     else
  244.     {
  245.         printf("\n\nLetter out of range!\n\n");
  246.         return(-1);
  247.     }
  248.         
  249. }
  250.  
  251.  
  252. /********************************************************************
  253. **
  254. **
  255. **
  256. ********************************************************************* */
  257.  
  258. int read_fil(num_dir,num_fil,num)
  259.  
  260. int *num_dir,*num_fil,*num;
  261.  
  262. {
  263.     int i,j,k;
  264.     FILE *fp;
  265.     char string[100];
  266.     int end=0,si=0,fi=0,num_read;
  267.  
  268.     List_Fil_Read=1;
  269.  
  270.     fp=fopen("list.fil","rt");
  271.     if(!fp)
  272.     {
  273.         printf("Could not find file 'list.fil'\n\n");
  274.         return(-1);
  275.     }
  276.  
  277.     i=0;
  278.     do
  279.     {
  280.         num_read=fscanf(fp,"%s",string);
  281.         if(strcmpi(string,"directories")==0)
  282.             si=1;
  283.         i+=1;
  284.     }while(i<MAX_DIR+MAX_FIL+2&&si==0&&num_read>0);
  285.  
  286.     i=end=0;
  287.     if(si=1) /* found 'directories' */
  288.     {
  289.         do
  290.         {
  291.             num_read=fscanf(fp,"%s",Dir[i]);
  292.             if(num_read<=0)
  293.                 end=1;
  294.             else if(strcmpi(Dir[i],"file_types")==0)
  295.             {
  296.                 end=1;
  297.                 fi=1;
  298.             }
  299.             if(end==0)
  300.                 i+=1;
  301.         }while(end==0&&i<MAX_DIR);
  302.         *num_dir=i;
  303.     }
  304.     end=i=0;
  305.     if(fi=1) /* found 'file_types' */
  306.     {
  307.         do
  308.         {
  309.             num_read=fscanf(fp,"%s",Fil[i]);
  310.             if(num_read<=0)
  311.                 end=1;
  312.             if(end==0)
  313.                 i+=1;
  314.         }while(end==0&&i<MAX_FIL);
  315.         *num_fil=i;
  316.     }
  317.     *num=*num_fil;
  318.     if(*num_dir>*num)*num=*num_dir;
  319.     fclose(fp);
  320. }
  321.  
  322. #endif
  323. /********************************************************************
  324. **
  325. **
  326. **
  327. ********************************************************************* */
  328.  
  329. int list_dir(what,which)
  330.  
  331. char *what,*which;
  332.  
  333. {
  334.     int i=0,j,k,p,l,e,n,m;
  335.     FILE *fp;
  336.     char string[100],directory[80],data[5][30];
  337.     int num_read,end=0,lines=0,l_extra=0,pages=1,p_extra=0,num=0,le;
  338.     char ans;
  339.     int val,eof=0;
  340.  
  341.     num=load_names(what);
  342.     if(num>0)
  343.     {
  344.         sort_name(num);
  345.         return(get_name(num,which));
  346.     }
  347.     else
  348.         return(-1);
  349. }
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356. /********************************************************************
  357. **
  358. **
  359. **
  360. ********************************************************************* */
  361.  
  362. int get_string(string,buffer,string1,string2,xc,yc,xs,ys,save,remove,
  363.         font,brite)
  364.  
  365. int xc,yc,xs,ys,save,remove;
  366. unsigned char *buffer;
  367. char *string1,*string2,*string;
  368. int font[128][25],brite;
  369.  
  370. {
  371.     int j,k;
  372.     int i=yc+1,ans;
  373.     int size=2;
  374.     int txc=xc,tyc=yc+31,txs=7,tys=15;
  375.     char ltr[2],tstring[100];
  376.     unsigned char buff[100];
  377.     double number;
  378.     int val;
  379.  
  380.     if(brite<0||brite>255)
  381.         brite=191;
  382.  
  383.     ltr[1]='\0';
  384.  
  385.     if(save==1)
  386.         save_box(0,0,buffer,xc,yc,xs,ys);
  387.     plot_font_h(brite,xc+2,yc+1,string1,size,font);
  388.     plot_font_h(brite,xc+2,yc+30/size+1,string2,size,font);
  389.     k=0;
  390.     do
  391.     {    
  392.         ans=getch();
  393.         if(ans==27)
  394.         {
  395.             if(remove==1)
  396.                 unsave_box(0,0,buffer,xc,yc,xs,ys);
  397.             return(0);
  398.         }
  399.         if(ans==0)
  400.         {
  401.             if(getch()==33)
  402.             {
  403.                 SetVideoMode(3);
  404.                 val=get_file_name(string,tstring);
  405.                 if(val>0)
  406.                 {
  407.                     SetVideoMode(480);
  408.                     set_lut('G');
  409.                     return(val);
  410.                 }
  411.                 else 
  412.                 {
  413.                     printf("No file chosen.  HIT ANY KEY TO CONTINUE!\n\n");
  414.                     getch();
  415.                     SetVideoMode(480);
  416.                     set_lut('G');
  417.                     return(0);
  418.                 }
  419.             }
  420.             else
  421.                 ans=' ';
  422.         }
  423.         i=yc+60/size+2;
  424.         paint_box(0,0,buff,txc,tyc,txs,tys);
  425.         if((ans>=' '&&ans<='}'))
  426.         {
  427.             string[k]=ans;
  428.             ltr[0]=ans;
  429.             plot_font_h(brite,txc,i,ltr,size,font);
  430.             k+=1;
  431.             txc+=7;
  432.         }
  433.         if(ans==8&&k>0)
  434.         {
  435.             string[k]='\0';
  436.             k-=1;
  437.             txc-=7;
  438.             paint_box(0,0,buff,txc,tyc,txs,tys);
  439.         }
  440.     }while(ans!=13);
  441.     string[k]='\0';
  442.     if(remove==1)
  443.         unsave_box(0,0,buffer,xc,yc,xs,ys);
  444.     return(k);
  445. }
  446.  
  447.  
  448.  
  449.  
  450.  
  451. /********************************************************************
  452. **
  453. **
  454. **
  455. ********************************************************************* */
  456.  
  457. char get_ans(buffer,string1,string2,xc,yc,xs,ys,save,remove,font,brite)
  458.  
  459. int xc,yc,xs,ys,save,remove;
  460. unsigned char *buffer;
  461. char *string1,*string2;
  462. int font[128][25],brite;
  463.  
  464. {
  465.     int i=yc+1,ans;
  466.     int size=2;
  467.  
  468.     if(brite<0||brite>255)
  469.         brite=191;
  470.  
  471.     if(save==1)
  472.         save_box(0,0,buffer,xc,yc,xs,ys);
  473.     plot_font_h(brite,xc+1,i,string1,size,font);
  474.     i+=30/size;
  475.     plot_font_h(brite,xc+1,i,string2,size,font);
  476.     i+=30/size;
  477.     ans=getch();
  478.     if(remove==1)
  479.         unsave_box(0,0,buffer,xc,yc,xs,ys);
  480.  
  481.     return(ans);
  482. }
  483.  
  484.  
  485.  
  486.  
  487.  
  488. /********************************************************************
  489. **
  490. **
  491. **
  492. ********************************************************************* */
  493.  
  494. void help(num)
  495.  
  496. int num;
  497.  
  498. {
  499.     int xc=10,yc=10;
  500.  
  501. /*    save_sub(xc-2,yc-2,COL*7+4,ROW*15+4,Vimage_Save1);
  502.     read_block(output,num);
  503.     plot_block(output,10,10);
  504.     getch();
  505.     recall_sub(xc-2,yc-2,COL*7+4,ROW*15+4,Vimage_Save1);*/
  506. }
  507.  
  508.  
  509.  
  510. /********************************************************************
  511. **
  512. **    WARNING!!!!  YOU MUST CALL decode_font() or set_files() before using
  513. **
  514. **     options:
  515. **
  516. **       -1 -- remove menu but get no answer
  517. **        0 -- return answer and set menu colors to greys
  518. **        1 -- return answer but leave colors alone
  519. **
  520. ********************************************************************* */
  521.  
  522. int do_menu(menu,num,xc,yc,start,back,words,boxs,font)
  523.  
  524. char *menu[];
  525. int num,xc,yc,start,back,words,boxs;
  526. int font[128][25];
  527.  
  528. {
  529.     int i,j,k;
  530.     char ans,ans2;
  531.     int len=0,l,size=2,val,valo;
  532.     int black=0,dgrey=back,lgrey=words,white=boxs;
  533.     int wide;
  534.  
  535.     for(k=0;k<num;k++)
  536.         if((l=strlen(menu[k]))>len)len=l;
  537.     if(len==0)return(-1);
  538.     wide=(len+1)*15/size+1;
  539.     if(((ScreenXs-1)-wide)<xc)xc=(ScreenXs-1)-wide;
  540.  
  541.     if((xc+(len+1)*15/size+1)<ScreenXs)
  542.     {
  543.         save_sub(xc,yc,(len+1)*15/size+1,30/size*num+1,Vimage_Save1);
  544.         paint_box(0,dgrey,Vimage_Buffer,xc,yc,(len+1)*15/size+1,30/size*num+1);
  545.         for(k=0;k<num;k++)
  546.         {    
  547.             box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
  548.             plot_font_h(lgrey,xc+15/size,yc+k*30/size+5/size,menu[k],size,font);
  549.         }
  550.         box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
  551.  
  552.         val=valo=start;
  553.         box(0,xc,yc+val*(30/size),white,(len+1)*15/size,30/size);
  554.         do
  555.         {
  556.             if((ans=getch())==0)
  557.             {
  558.                 ans2=getch();
  559.                 if(ans2==50)
  560.                 {
  561.                     recall_sub(xc,yc,(len+1)*15/size+1,30/size*num+1
  562.                             ,Vimage_Save1);
  563.                     getch();
  564.                     paint_box(0,dgrey,Vimage_Buffer,
  565.                         xc,yc,(len+1)*15/size+1,30/size*num+1);
  566.                     for(k=0;k<num;k++)
  567.                     {    
  568.                         plot_font_h(lgrey,xc+15/size,
  569.                                     yc+k*30/size+5/size,menu[k],size,font);
  570.                     }
  571.                 }
  572.                 if(ans2=='H')
  573.                 {
  574.                     if(val>0)val-=1;
  575.                     else val=num-1;
  576.                 }
  577.                 if(ans2=='P')
  578.                 {
  579.                     if(val<num-1)val+=1;
  580.                     else val=0;
  581.                 }
  582.             }
  583.  
  584.             for(i=0;i<num;i++)
  585.                 if(ans==menu[i][0])
  586.                 {
  587.                     val=i;
  588.                     ans=13;
  589.                 }
  590.  
  591.             box(0,xc,yc+valo*(30/size),dgrey,(len+1)*15/size,30/size);
  592.             valo=val;
  593.             box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
  594.             box(0,xc,yc+val*(30/size),white,(len+1)*15/size,30/size);
  595.         }while(ans!=13);
  596.     }
  597.     box(0,xc,yc,dgrey,(len+1)*15/size,30/size*num);
  598.     box(0,xc,yc+val*(30/size),lgrey,(len+1)*15/size,30/size);
  599.  
  600.     recall_sub(xc,yc,(len+1)*15/size+1,30/size*num+1,Vimage_Save1);
  601.     return(val);
  602. }
  603.  
  604.  
  605. /********************************************************************
  606. **
  607. **    WARNING!!!!  YOU MUST CALL decode_font() or set_files() before using
  608. **
  609. **     options:
  610. **
  611. **       -1 -- remove menu but get no answer
  612. **        0 -- return answer and set menu colors to greys
  613. **        1 -- return answer but leave colors alone
  614. **
  615. ********************************************************************* */
  616.  
  617. int t_do_menu(menu,num,xc,yc,start,back,words,boxs,font,off_on)
  618.  
  619. char menu[][2][50];
  620. int num,xc,yc,start,back,words,boxs;
  621. int font[128][25],*off_on;
  622.  
  623. {
  624.     int i,j,k;
  625.     char ans,ans2;
  626.     int len=0,l,size=2,val,valo;
  627.     int black=0,dgrey=back,lgrey=words,white=boxs;
  628.     int wide;
  629.  
  630.     for(k=0;k<num;k++)
  631.         if((l=strlen(menu[k][0]))>len)len=l;
  632.     if(len==0)return(-1);
  633.     wide=(len+1)*15/size+1;
  634.     if(((ScreenXs-1)-wide)<xc)xc=(ScreenXs-1)-wide;
  635.  
  636.     if((xc+(len+1)*15/size+1)<ScreenXs)
  637.     {
  638.         save_sub(xc,yc,(len+1)*15/size+1,30/size*num+1,Vimage_Save1);
  639.         paint_box(0,dgrey,Vimage_Buffer,xc,yc,(len+1)*15/size+1,30/size*num+1);
  640.         for(k=0;k<num-3;k++)
  641.         {    
  642.             box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
  643.             plot_font_h(lgrey,xc+15/size,yc+k*30/size+5/size,menu[k][off_on[k]],
  644.                 size,font);
  645.         }
  646.         for(k=num-3;k<num;k++)
  647.         {    
  648.             box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
  649.             plot_font_h(lgrey,xc+15/size,yc+k*30/size+5/size,menu[k][0],
  650.                 size,font);
  651.         }
  652.         box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
  653.  
  654.         val=valo=start;
  655.         box(0,xc,yc+val*(30/size),white,(len+1)*15/size,30/size);
  656.         do
  657.         {
  658.             ans=getch();
  659.             if(ans==13)
  660.             {
  661.                 if(val<num-3)
  662.                 {
  663.                     if(off_on[val]==0)
  664.                         off_on[val]=1;
  665.                     else
  666.                         off_on[val]=0;
  667.                 }
  668.                 if(val==num-3)
  669.                     for(k=0;k<num-3;k++)
  670.                         off_on[k]=1;
  671.                 if(val==num-2)
  672.                     for(k=0;k<num-3;k++)
  673.                         off_on[k]=0;
  674.                 paint_box(0,dgrey,Vimage_Buffer,xc,yc,
  675.                     (len+1)*15/size+1,30/size*num+1);
  676.                 for(k=0;k<num-3;k++)
  677.                 {    
  678.                     box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
  679.                     plot_font_h(lgrey,xc+15/size,yc+k*30/size+5/size,
  680.                             menu[k][off_on[k]],size,font);
  681.                 }
  682.                 for(k=num-3;k<num;k++)
  683.                 {    
  684.                     box(0,xc,yc+k*(30/size),dgrey,(len+1)*15/size,30/size);
  685.                     plot_font_h(lgrey,xc+15/size,yc+k*30/size+5/size,
  686.                             menu[k][0],size,font);
  687.                 }
  688.                 box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
  689.             }
  690.             if(ans==13&&val==num-1)
  691.                 ans=27;
  692.             if(ans==0)
  693.             {
  694.                 ans2=getch();
  695.                 if(ans2==50)
  696.                 {
  697.                     recall_sub(xc,yc,(len+1)*15/size+1,30/size*num+1
  698.                             ,Vimage_Save1);
  699.                     getch();
  700.                     paint_box(0,dgrey,Vimage_Buffer,
  701.                         xc,yc,(len+1)*15/size+1,30/size*num+1);
  702.                     for(k=0;k<num;k++)
  703.                     {    
  704.                         plot_font_h(lgrey,xc+15/size,
  705.                             yc+k*30/size+5/size,menu[k][off_on[k]],size,font);
  706.                     }
  707.                 }
  708.                 if(ans2=='H')
  709.                 {
  710.                     if(val>0)val-=1;
  711.                     else val=num-1;
  712.                 }
  713.                 if(ans2=='P')
  714.                 {
  715.                     if(val<num-1)val+=1;
  716.                     else val=0;
  717.                 }
  718.             }
  719.             for(i=0;i<num;i++)
  720.                 if(ans==menu[i][0][0])
  721.                 {
  722.                     val=i;
  723.                     ans=27;
  724.                 }
  725.             box(0,xc,yc+valo*(30/size),dgrey,(len+1)*15/size,30/size);
  726.             valo=val;
  727.             box(0,xc,yc,lgrey,(len+1)*15/size,30/size*num);
  728.             box(0,xc,yc+val*(30/size),white,(len+1)*15/size,30/size);
  729.         }while(ans!=27);
  730.     }
  731.     box(0,xc,yc,dgrey,(len+1)*15/size,30/size*num);
  732.     box(0,xc,yc+val*(30/size),lgrey,(len+1)*15/size,30/size);
  733.  
  734.     recall_sub(xc,yc,(len+1)*15/size+1,30/size*num+1,Vimage_Save1);
  735.     return(val);
  736. }
  737.  
  738.  
  739. /********************************************************************
  740. **
  741. **
  742. **
  743. ********************************************************************* */
  744.  
  745. void save_sub(xc,yc,xs,ys,fp)
  746.  
  747. int xc,yc,xs,ys;
  748. FILE *fp;
  749.  
  750. {
  751.     int i,j,k;
  752.  
  753.     rewind(fp);
  754.  
  755.     fwrite((char *)&ys,sizeof(int),1,fp);
  756.     fwrite((char *)&xs,sizeof(int),1,fp);
  757.  
  758.     for(i=0;i<ys;i++)
  759.     {
  760.         getrow(3,xc,xc+xs-1,i+yc,Vimage_Buffer);
  761.         fwrite((char *)Vimage_Buffer,sizeof(char),xs,fp);
  762.     }
  763. }
  764.  
  765. /********************************************************************
  766. **
  767. **
  768. **
  769. ********************************************************************* */
  770.  
  771. void recall_sub(xc,yc,xs,ys,fp)
  772.  
  773. int xc,yc,xs,ys;
  774. FILE *fp;
  775.  
  776. {
  777.     int i,j,k;
  778.  
  779.     xs=ys=0;
  780.  
  781.     rewind(fp);
  782.  
  783.     fread((char *)&ys,sizeof(int),1,fp);
  784.     fread((char *)&xs,sizeof(int),1,fp);
  785.  
  786.     if(xc+xs>ScreenXs)xc=ScreenXs-xs;
  787.     if(yc+ys>ScreenYs)yc=ScreenYs-ys;
  788.     if(xc<0||yc<0)return;
  789.  
  790.     for(i=0;i<ys;i++)
  791.     {
  792.         fread((char *)Vimage_Buffer,sizeof(char),xs,fp);
  793.         PlotLine(i+yc,xc,i+yc,xc+xs-1,Vimage_Buffer);
  794.     }
  795. }
  796.  
  797.  
  798. /********************************************************************
  799. **
  800. **    paints a box and saves contents in buffer
  801. **
  802. ********************************************************************* */
  803.  
  804. void save_box(hue,val,buffer,xc,yc,xsize,ysize)
  805.  
  806. int hue,val,xc,yc,xsize,ysize;
  807.  
  808. unsigned char *buffer;
  809.  
  810. {
  811.     int i,j,k,x2,y2;
  812.  
  813.     x2=xc+xsize-1;
  814.     y2=yc+ysize;
  815.     for(k=0;k<xsize;k++)Vimage_Buffer[k]=val;
  816.     for(j=0;j<ysize;j++)
  817.     {
  818.         getrow(3,xc,x2,j+yc,buffer+j*xsize);
  819.         PlotLine(j+yc,xc,j+yc,x2,Vimage_Buffer);
  820.     }
  821. }
  822.  
  823. /********************************************************************
  824. **
  825. **    unpaints a box and saves contents in buffer
  826. **
  827. ********************************************************************* */
  828.  
  829. void unsave_box(hue,val,buffer,xc,yc,xsize,ysize)
  830.  
  831. int hue,val,xc,yc,xsize,ysize;
  832.  
  833. unsigned char *buffer;
  834.  
  835. {
  836.     int i,j,k,x2,y2;
  837.  
  838.     x2=xc+xsize-1;
  839.     y2=yc+ysize;
  840.     for(j=0;j<ysize;j++)
  841.     {
  842.         PlotLine(j+yc,xc,j+yc,x2,buffer+j*xsize);
  843.     }
  844. }
  845.  
  846. /********************************************************************
  847. **
  848. **
  849. **
  850. ********************************************************************* */
  851.  
  852. int limit_area_all(x,y,xsize,ysize,speed,max_x,max_y,iop,buffer,lo,hi,cent)
  853.  
  854. int *x,*y,*xsize,*ysize,*speed,max_x,max_y,iop,lo,hi,cent;
  855. unsigned char *buffer;
  856.  
  857. {
  858.     char ans;
  859.     int size=0,xo,yo,menu=1;
  860.     int spd=*speed;
  861.     int dir=1;
  862.  
  863.     xo=*x;
  864.     yo=*y;
  865.  
  866.     tbox_val(3,*x,*y,*xsize,*ysize,buffer,lo,hi,cent);
  867.     do
  868.     {
  869.         ans=getpad(&size,x,y,speed,menu);    /* use number pad to move box */
  870.         if(ans=='c')dir*=(-1);
  871.         spd=*speed*dir;
  872.         menu=0;    /* turn off menu print */
  873.         unbox(3,xo,yo,*xsize,*ysize,buffer); /* remove old box */
  874.         if(iop==1)            /* change x size */
  875.         {
  876.             if(ans=='x')
  877.                 *xsize+=spd;
  878.             if(ans=='y')
  879.                 *ysize+=spd;
  880.             if(ans=='N'||ans=='s')*xsize-=*speed;
  881.             if(ans=='W'||ans=='l')*xsize+=*speed;
  882.             if(ans=='S'||ans=='s')*ysize-=*speed;
  883.             if(ans=='H'||ans=='l')*ysize+=*speed;
  884.             if(*xsize>max_x)*xsize=max_x;
  885.             if(*xsize<0)*xsize=2;
  886.             if(*ysize>max_y)*ysize=max_y;
  887.             if(*ysize<0)*ysize=2;
  888.         }
  889.         if(*x<0)*x=0;                            /* make sure all is on screen */
  890.         if(*y<0)*y=0;
  891.         if(*x+*xsize>max_x)*x=max_x-*xsize;
  892.         if(*y+*ysize>max_y)*y=max_y-*ysize;
  893.         tbox_val(3,*x,*y,*xsize,*ysize,buffer,lo,hi,cent);
  894.         xo=*x;                                    /* set old location */
  895.         yo=*y;
  896.     }while(ans!=13&&ans!=27);
  897.     unbox(3,xo,yo,*xsize,*ysize,buffer); /* remove old box */
  898.  
  899.     return(ans);
  900. }
  901.  
  902.  
  903.  
  904. /********************************************************************
  905. **
  906. **
  907. **
  908. ********************************************************************* */
  909.  
  910. int limit_area(x,y,xsize,ysize,speed,maxbox,iop,buffer)
  911.  
  912. int *x,*y,*xsize,*ysize,*speed,maxbox,iop;
  913. unsigned char *buffer;
  914.  
  915. {
  916.     char ans;
  917.     int size=0,xo,yo,menu=1;
  918.     int spd=*speed;
  919.     int dir=1;
  920.  
  921.     if(*xsize>ScreenXs)
  922.         *xsize=ScreenXs;
  923.     if(*x+*xsize>=ScreenXs)
  924.         *x=ScreenXs-*xsize;
  925.     if(*ysize>ScreenYs)
  926.         *ysize=ScreenYs;
  927.     if(*y+*ysize>=ScreenYs)
  928.         *y=ScreenYs-*ysize;
  929.     xo=*x;
  930.     yo=*y;
  931.     tbox(3,*x,*y,*xsize,*ysize,buffer); /* plot 1st box on overlay */
  932.     do
  933.     {
  934.         ans=getpad(&size,x,y,speed,menu);    /* use number pad to move box */
  935.         if(ans=='c')dir*=(-1);
  936.         spd=*speed*dir;
  937.         menu=0;    /* turn off menu print */
  938.         unbox(3,xo,yo,*xsize,*ysize,buffer); /* remove old box */
  939.         if(iop==1)            /* change x size */
  940.         {
  941.             if(ans=='x')
  942.                 *xsize+=spd;
  943.             if(ans=='y')
  944.                 *ysize+=spd;
  945.             if(ans=='n')*xsize-=*speed;
  946.             if(ans=='w')*xsize+=*speed;
  947.             if(ans=='s')*ysize-=*speed;
  948.             if(ans=='h')*ysize+=*speed;
  949.             if(*xsize>maxbox)*xsize=maxbox;
  950.             if(*xsize<0)*xsize=8;
  951.             if(*ysize>maxbox)*ysize=maxbox;
  952.             if(*ysize<0)*ysize=8;
  953.         }
  954.         if(*x<0)*x=0;                            /* make sure all is on screen */
  955.         if(*y<0)*y=0;
  956.         if(*x+*xsize>(ScreenXs-1))*x=(ScreenXs-1)-*xsize;
  957.         if(*y+*ysize>(ScreenYs-1))*y=(ScreenYs-1)-*ysize;
  958.         tbox(3,*x,*y,*xsize,*ysize,buffer);  /* plot new box on overlay */        
  959.         xo=*x;                                    /* set old location */
  960.         yo=*y;
  961.     }while(ans!=83&&ans!=13&&ans!=27);
  962.     unbox(3,xo,yo,*xsize,*ysize,buffer); /* remove old box */
  963.  
  964.     return(ans);
  965. }
  966.  
  967.  
  968.  
  969.  
  970. /* ******************************************************************
  971. **
  972. **    draw a line on the image
  973. **
  974. ********************************************************************* */
  975.  
  976. void plotlnsym(hue,sym,x1,y1,x2,y2,val)
  977.  
  978. int hue;    /* image plane */
  979. int sym; /* line number */
  980. int x1,y1;    /* coordinates of 1st point */
  981. int x2,y2;    /* coordinates of 2nd point */
  982. int val;    /* brightness of line */
  983.  
  984. {
  985.     int n=0,nn;
  986.     int   i, j, k, numx, numy;
  987.     float x, y, dy, dx;
  988.  
  989.     if(hue<0 || hue>3) return;
  990.     if(val<0 || val >255) return;
  991.  
  992.     numx = ( x2 > x1 ) ? x2-x1 : x1-x2;
  993.     numy = ( y2 > y1 ) ? y2-y1 : y1-y2;
  994.  
  995.     if(numx==0 && numy==0) return;
  996.  
  997.     if( numx>numy ) {
  998.         dy = (float)(y2-y1)/(float)(x2-x1);
  999.         dx = (x2>x1) ? 1.0 : -1.0;
  1000.         i = x = x1;
  1001.         j = y = y1;
  1002.         for(k=0;k<=(numx);k++)
  1003.         {
  1004.             nn=n++%line[sym].num;
  1005.             WritePixel(j,i,val*line[sym].pat[nn]);
  1006.             x += dx;
  1007.             y += dy*dx;
  1008.             if(dy>=0.0)
  1009.             {
  1010.                 i = x;
  1011.                 j = y;
  1012.             }
  1013.             else
  1014.             {
  1015.                 i = x;
  1016.                 j = y+0.5;
  1017.             }
  1018.         }
  1019.     }
  1020.     else{
  1021.         dx = (float)(x2-x1)/(float)(y2-y1);
  1022.         dy = (y2>y1) ? 1.0 : -1.0;
  1023.         i = x = x1;
  1024.         j = y = y1;
  1025.         for(k=0;k<=(numy);k++)
  1026.         {
  1027.             nn=n++%line[sym].num;
  1028.             WritePixel(j,i,val*line[sym].pat[nn]);
  1029.             x += dx*dy;
  1030.             y += dy;
  1031.             if(dx>=0.0)
  1032.             {
  1033.                 i = x;
  1034.                 j = y;
  1035.             }
  1036.             else
  1037.             {
  1038.                 i = x+0.5;
  1039.                 j = y;
  1040.             }
  1041.         }
  1042.     }
  1043.  
  1044. }
  1045.  
  1046.  
  1047.  
  1048.  
  1049.  
  1050. /********************************************************************
  1051. **
  1052. **
  1053. **
  1054. ********************************************************************* */
  1055.  
  1056. int plotsym(hue,num,x,y,size,val)
  1057.  
  1058. int hue,num,x,y,size,val;
  1059.  
  1060. {
  1061.     int i,j,k;
  1062.     int x1,y1,x2,y2;
  1063.     int dist,sign;
  1064.  
  1065.     if(num>=NUMSYM)return;
  1066.  
  1067.     if(size<1)size=1;
  1068.  
  1069.     for(i=0;i<sym[num].num;i++)
  1070.     {
  1071.         dist=abs(sym[num].side[i][0]);
  1072.         sign=(sym[num].side[i][0]>0)?1:-1;
  1073.         x1=dist;
  1074.         x1*=size;
  1075.         x1/=sym[num].scale;
  1076.         x1*=sign;
  1077.  
  1078.         dist=abs(sym[num].side[i][1]);
  1079.         sign=(sym[num].side[i][1]>0)?1:-1;
  1080.         y1=dist;
  1081.         y1*=size;
  1082.         y1/=sym[num].scale;
  1083.         y1*=sign;
  1084.  
  1085.         dist=abs(sym[num].side[i+1][0]);
  1086.         sign=(sym[num].side[i+1][0]>0)?1:-1;
  1087.         x2=dist;
  1088.         x2*=size;
  1089.         x2/=sym[num].scale;
  1090.         x2*=sign;
  1091.  
  1092.         dist=abs(sym[num].side[i+1][1]);
  1093.         sign=(sym[num].side[i+1][1]>0)?1:-1;
  1094.         y2=dist;
  1095.         y2*=size;
  1096.         y2/=sym[num].scale;
  1097.         y2*=sign;
  1098.         DrawVector(y+y1,x+x1,y+y2,x+x2,val);
  1099.     }
  1100.     return(NUMSYM);
  1101. }
  1102.  
  1103.  
  1104.  
  1105.  
  1106. /********************************************************************
  1107. **
  1108. **    paints a box
  1109. **
  1110. ********************************************************************* */
  1111.  
  1112. void paint_box(hue,val,buffer,xc,yc,xsize,ysize)
  1113.  
  1114. int hue,val,xc,yc,xsize,ysize;
  1115.  
  1116. unsigned char *buffer;
  1117.  
  1118. {
  1119.     int i,j,k,x2,y2;
  1120.  
  1121.     x2=xc+xsize-1;
  1122.     y2=yc+ysize;
  1123.  
  1124. /*    for(k=0;k<xsize;k++)buffer[k]=val;*/
  1125.  
  1126.     for(j=yc;j<y2;j++)
  1127.     {
  1128.         DrawVector(j,xc,j,x2,val);
  1129. /*        PlotLine(j,xc,j,x2,buffer);*/
  1130.     }
  1131. }
  1132.  
  1133.  
  1134. /********************************************************************
  1135. **
  1136. **    unboxes
  1137. **
  1138. ********************************************************************* */
  1139.  
  1140. void unbox(hue,xc,yc,xsize,ysize,buffer)
  1141.  
  1142. int hue,xc,yc,xsize,ysize;
  1143. unsigned char *buffer;
  1144.  
  1145. {
  1146.     int x,y;
  1147.     unsigned char val;
  1148.  
  1149.     if(xsize<=1&&ysize<=1)
  1150.     {
  1151.         WritePixel(y,x,*buffer);
  1152.         return;
  1153.     }
  1154.  
  1155.     if(xsize>1)
  1156.         for(x=xc;x<xc+xsize;x++)
  1157.         {
  1158.             y=yc;
  1159.             WritePixel(y,x,*buffer++);
  1160.         }
  1161.     if(ysize>2)
  1162.         for(y=yc+1;y<yc+ysize-1;y++)
  1163.         {
  1164.             x=xc+xsize-1;
  1165.             WritePixel(y,x,*buffer++);
  1166.         }
  1167.     if(xsize>1)
  1168.         for(x=xc;x<xc+xsize;x++)
  1169.         {
  1170.             y=yc+ysize-1;
  1171.             WritePixel(y,x,*buffer++);
  1172.         }
  1173.     if(ysize>2)
  1174.         for(y=yc+1;y<yc+ysize-1;y++)
  1175.         {
  1176.             x=xc;
  1177.             WritePixel(y,x,*buffer++);
  1178.         }
  1179. }
  1180.  
  1181.  
  1182. /********************************************************************
  1183. **
  1184. **    creates a box on color plane hue which can be erased by unbox()
  1185. **
  1186. ********************************************************************* */
  1187.  
  1188. int tbox_val(hue,xc,yc,xsize,ysize,buffer,low_color,high_color,center_val)
  1189.  
  1190. int hue,xc,yc,xsize,ysize,low_color,high_color,center_val;
  1191. unsigned char *buffer;
  1192.  
  1193. {
  1194.     int x,y;
  1195.     unsigned char val;
  1196.     
  1197.     if(xsize<=1&&ysize<=1)
  1198.     {
  1199.         *buffer=getpt(hue,x,y);
  1200.         val=(*buffer>center_val)?low_color:high_color;
  1201.         WritePixel(y,x,val);
  1202.         return;
  1203.     }
  1204.  
  1205.     if(xsize>1)
  1206.         for(x=xc;x<xc+xsize;x++)
  1207.         {
  1208.             y=yc;
  1209.             *buffer=getpt(hue,x,y);
  1210.             val=(*buffer>center_val)?low_color:high_color;
  1211.             buffer+=1;
  1212.             WritePixel(y,x,val);
  1213.         }
  1214.     if(ysize>2)
  1215.         for(y=yc+1;y<yc+ysize-1;y++)
  1216.         {
  1217.             x=xc+xsize-1;
  1218.             *buffer=getpt(hue,x,y);
  1219.             val=(*buffer>center_val)?low_color:high_color;
  1220.             buffer+=1;
  1221.             WritePixel(y,x,val);
  1222.         }
  1223.     if(xsize>1)
  1224.         for(x=xc;x<xc+xsize;x++)
  1225.         {
  1226.             y=yc+ysize-1;
  1227.             *buffer=getpt(hue,x,y);
  1228.             val=(*buffer>center_val)?low_color:high_color;
  1229.             buffer+=1;
  1230.             WritePixel(y,x,val);
  1231.         }
  1232.     if(ysize>2)
  1233.         for(y=yc+1;y<yc+ysize-1;y++)
  1234.         {
  1235.             x=xc;
  1236.             *buffer=getpt(hue,x,y);
  1237.             val=(*buffer>center_val)?low_color:high_color;
  1238.             buffer+=1;
  1239.             WritePixel(y,x,val);
  1240.         }
  1241. }
  1242.  
  1243.  
  1244.  
  1245.  
  1246. /********************************************************************
  1247. **
  1248. **    creates a box on color plane hue which can be erased by unbox()
  1249. **
  1250. ********************************************************************* */
  1251.  
  1252. void tbox(hue,xc,yc,xsize,ysize,buffer)
  1253.  
  1254. int hue,xc,yc,xsize,ysize;
  1255. unsigned char *buffer;
  1256.  
  1257. {
  1258.     int x,y;
  1259.     unsigned char val;
  1260.     
  1261.     if(xsize<=1&&ysize<=1)
  1262.     {
  1263.         *buffer=getpt(hue,x,y);
  1264.         val=(*buffer<127)?243:3;
  1265.         WritePixel(y,x,val);
  1266.         return;
  1267.     }
  1268.  
  1269.     if(xsize>1)
  1270.         for(x=xc;x<xc+xsize;x++)
  1271.         {
  1272.             y=yc;
  1273.             *buffer=getpt(hue,x,y);
  1274.             val=(*buffer<127)?243:3;
  1275.             buffer+=1;
  1276.             WritePixel(y,x,val);
  1277.         }
  1278.     if(ysize>2)
  1279.         for(y=yc+1;y<yc+ysize-1;y++)
  1280.         {
  1281.             x=xc+xsize-1;
  1282.             *buffer=getpt(hue,x,y);
  1283.             val=(*buffer<127)?243:3;
  1284.             buffer+=1;
  1285.             WritePixel(y,x,val);
  1286.         }
  1287.     if(xsize>1)
  1288.         for(x=xc;x<xc+xsize;x++)
  1289.         {
  1290.             y=yc+ysize-1;
  1291.             *buffer=getpt(hue,x,y);
  1292.             val=(*buffer<127)?243:3;
  1293.             buffer+=1;
  1294.             WritePixel(y,x,val);
  1295.         }
  1296.     if(ysize>2)
  1297.         for(y=yc+1;y<yc+ysize-1;y++)
  1298.         {
  1299.             x=xc;
  1300.             *buffer=getpt(hue,x,y);
  1301.             val=(*buffer<127)?243:3;
  1302.             buffer+=1;
  1303.             WritePixel(y,x,val);
  1304.         }
  1305. }
  1306.  
  1307. /********************************************************************
  1308. **
  1309. **    find pixel values
  1310. **
  1311. ********************************************************************* */
  1312.  
  1313. void pix_val(fx,fy)
  1314.  
  1315. int fx,fy;            /* starting point of cursor */
  1316.  
  1317. {
  1318.  
  1319.     int ans,size,speed,x,y,xo,yo,k;
  1320.     static unsigned char tbuff[200];
  1321.  
  1322.     speed=5;
  1323.     size=0;
  1324.     xo=x=fx;
  1325.     yo=y=fy;
  1326.     tcursor(3,x,y,5,tbuff);
  1327.     while((ans=getpad(&size,&x,&y,&speed,0))!=83)
  1328.     {
  1329.         uncursor(3,xo,yo,5,tbuff);
  1330.         tcursor(3,x,y,5,tbuff);
  1331.         xo=x;
  1332.         yo=y;
  1333. /*        if(ans==13)    
  1334.             printf("x = %3d  y = %3d     r = %3d  g = %3d  b = %3d  o = %3d\n",
  1335.                 x,y,getpt(0,x,y),getpt(1,x,y),getpt(2,x,y),getpt(3,x,y));*/
  1336.  
  1337.     }
  1338.     uncursor(3,xo,yo,5,tbuff);
  1339.     return;
  1340. }
  1341.  
  1342.  
  1343. /********************************************************************
  1344. **  get_row reads a line segment from the video buffer into the
  1345. **  callers buffer
  1346. **
  1347. ********************************************************************* */
  1348.  
  1349. void getrow(hue,x1,x2,y,buffer)
  1350.  
  1351. int hue;
  1352. unsigned char far *buffer;
  1353. unsigned int x1;  /* beginning column to read             */
  1354. unsigned int x2;  /* ending column to read                */
  1355. unsigned int y ;  /* row to read                          */
  1356. {
  1357.     if(y<0||y>=ScreenYs)
  1358.         return;
  1359.     if(x1<0||x2>=ScreenXs||x1>x2)
  1360.         return;
  1361.  
  1362.     ReadLine(y,x1,y,x2,buffer);
  1363. }
  1364.  
  1365.  
  1366. /********************************************************************
  1367. **  get_row reads a line segment from the video buffer into the
  1368. **  callers buffer
  1369. **
  1370. ********************************************************************* */
  1371.  
  1372. void paintcol(hue,x,y1,y2,val)
  1373.  
  1374. int hue;
  1375. int val;
  1376. unsigned int y1;  /* beginning row to read             */
  1377. unsigned int y2;  /* ending row to read                */
  1378. unsigned int x ;  /* column to read                          */
  1379. {
  1380.     DrawVector(y1,x,y2,x,val);
  1381. }
  1382.  
  1383.  
  1384. /********************************************************************
  1385. **
  1386. **    plot a row of data
  1387. **
  1388. ********************************************************************* */
  1389.  
  1390. int plotrow(hue,x1,x2,y,buffer)
  1391.  
  1392. unsigned char *buffer;
  1393. int hue,x1,x2,y;
  1394.  
  1395. {
  1396.     int status=1;
  1397.  
  1398.     if(y<0||y>=ScreenYs)
  1399.         return(-1);
  1400.     if(x1<0||x2>=ScreenXs||x1>x2)
  1401.         return(-1);
  1402.     PlotLine(y,x1,y,x2,buffer);
  1403.     return(status);
  1404. }
  1405.  
  1406.  
  1407. /* ******************************************************************
  1408. **
  1409. **    plots a point at coordinates x and y with gun hue and brightness val
  1410. **
  1411. **    functions called: -- none
  1412. **
  1413. **    return:
  1414. **         1 = point plotted
  1415. **        -1 = point not plotted
  1416. ********************************************************************* */
  1417.  
  1418. int plotpt(hue,x,y,val)
  1419.  
  1420. int hue;    /* color plane -- 0-3 */
  1421. int x,y;    /* pixel coordinates */
  1422. int val;    /* brighness of pixel 0-255 */
  1423.  
  1424. {
  1425.     int status;
  1426.     
  1427.     status = -1;
  1428.     if(hue<0 || hue>3) return(status);
  1429.     if(val<0 || val >255) return(status);
  1430.     if(x<0||x>=ScreenXs) return(status);
  1431.     if(y<0||y>=ScreenYs) return(status);
  1432.     status = 1;
  1433.     WritePixel(y,x,val);
  1434.     return(status);
  1435. }
  1436.  
  1437.  
  1438.  
  1439. /* ******************************************************************
  1440. **
  1441. **    plots a string(hue,val,x,y,string,size) vertical
  1442. **
  1443. **    functions called:
  1444. **        plotpt();
  1445. **
  1446. ********************************************************************* */
  1447.  
  1448. void plot_font_v(val,x,y,string,size,font)
  1449.  
  1450. int val;    /* brightness of redm green and blue */
  1451. int x,y;                /* location of upper right corner of 1st letter */
  1452. int size;                /* size 1 = full size  2 = 1/2 size  3 = 1/3 size */
  1453. char string[80];        /* text to plot */
  1454. int font[128][25];    /* binary font maps */
  1455.  
  1456. {
  1457.     int i,j,k,l,m,n;
  1458.     int mask;
  1459.  
  1460.     n = 0;
  1461.     while(string[n]!='\0'){
  1462.         for(l=0;l<25;l++){
  1463.             k = string[n];
  1464.             mask = 512;
  1465.             for(m=0;m<10;m++) 
  1466.             {
  1467.                 if(font[k][l]&mask)
  1468.                 {
  1469.                     if(l%size == 0) 
  1470.                         plotpt(0,x+l/size,y-m/size,val);
  1471.  
  1472. /*                        WritePixel(y-m/size,x+l/size,val);*/
  1473.                 }
  1474.                 mask /= 2;
  1475.             }
  1476.         }
  1477.         n++;
  1478.         y -= 15/size;
  1479.     }
  1480. }
  1481.  
  1482. /* ******************************************************************
  1483. **
  1484. **    plots a string(hue,val,x,y,string,size) horizontal
  1485. **
  1486. **    functions called:
  1487. **        plotpt();
  1488. **
  1489. ********************************************************************* */
  1490.  
  1491. void plot_font_h(val,x,y,string,size,font)
  1492.  
  1493. int val;                    /* color to be plotted */
  1494. int x,y;                    /* location of upper right corner of 1st letter */
  1495. int size;                /* size 1 = full size  2 = 1/2 size  3 = 1/3 size */
  1496. char *string;            /* text to plot */
  1497. int font[128][25];    /* binary font maps */
  1498.  
  1499. {
  1500.     int i,j,k,l,m,n;
  1501.     int mask;
  1502.  
  1503.     n = 0;
  1504.     while(string[n]!='\0')
  1505.     {
  1506.         for(l=0;l<25;l++)
  1507.         {
  1508.             k = string[n];
  1509.             mask = 512;
  1510.             for(m=0;m<10;m++) 
  1511.             {
  1512.                 if(font[k][l]&mask) 
  1513.                 {
  1514.                     if(l%size == 0) 
  1515.                     {
  1516.                         plotpt(0,x+m/size,y+l/size,val);
  1517. /*                        WritePixel(y+l/size,x+m/size,val);*/
  1518.                     }
  1519.                 }
  1520.                 mask /= 2;
  1521.             }
  1522.         }
  1523.         n++;
  1524.         x += 15/size;
  1525.     }
  1526.  
  1527. }
  1528.  
  1529. /* ******************************************************************
  1530. **
  1531. **    plots a string(hue,val,x,y,string,size,rot) rotated rot degrees
  1532. **
  1533. **    functions called:
  1534. **        plotpt();
  1535. **
  1536. ********************************************************************* */
  1537.  
  1538. int plot_font_rot(val,x,y,string,size,font,rot)
  1539.  
  1540. int val;                    /* color to be plotted */
  1541. int x,y;                    /* location of upper right corner of 1st letter */
  1542. int size;                /* size 1 = full size  2 = 1/2 size  3 = 1/3 size */
  1543. char *string;            /* text to plot */
  1544. int font[128][25];    /* binary font maps */
  1545. double rot;                /* rotation uo from horizontal (degrees) */
  1546.  
  1547. {
  1548.     int i,j,k,l,m,n;
  1549.     int mask;
  1550.     double dx=x,dy=y,dl,dm,dsize=size;
  1551.     double cosrot=cos(rot*DEG_RAD),sinrot=sin(rot*DEG_RAD);
  1552.     int ix,iy;
  1553.     
  1554.     n = 0;
  1555.     while(string[n]!='\0')
  1556.     {
  1557.         for(l=0;l<25;l++)
  1558.         {
  1559.             dl=l;
  1560.             k = string[n];
  1561.             mask = 512;
  1562.             for(m=0;m<10;m++) 
  1563.             {
  1564.                 dm=m;
  1565.                 if(font[k][l]&mask) 
  1566.                 {
  1567.                     ix=dx+dm/dsize*cosrot+dl/dsize*sinrot;
  1568.                     iy=dy+dl/dsize*cosrot-dm/dsize*sinrot;
  1569.                     plotpt(0,ix,iy,val);
  1570. /*                    WritePixel(y+l/size,x+m/size,val);*/
  1571.                 }
  1572.                 mask /= 2;
  1573.             }
  1574.         }
  1575.         n++;
  1576.         dx+=15/dsize*cosrot;
  1577.         dy-=15/dsize*sinrot;
  1578.     }
  1579. }
  1580.  
  1581.  
  1582. /* ******************************************************************
  1583. **    
  1584. **    decodes 'font.raw' and makes 'font.hex'
  1585. **
  1586. **    functions called:
  1587. **        read();    requires -- <io.h>
  1588. **        open();              <fcntl.h> <sys\type.h> <sys\stat.h> 
  1589. **                                    <io.h> 
  1590. **        close();                    <io.h>
  1591. **
  1592. ********************************************************************* */
  1593.         
  1594. void decode_font(font)
  1595.  
  1596. int font[128][25];    /* binary font maps */
  1597.  
  1598. {
  1599.     int ffp;
  1600.     ffp = open("font.hex",O_RDONLY|O_BINARY);
  1601.     read(ffp,(char *)font,6400);
  1602.     close(ffp);
  1603.     Vimage_Save1=fopen("image1.sav","w+b");
  1604.     setbuf(Vimage_Save1,Vi_Inbuff1);
  1605.     Vimage_Save2=fopen("image2.sav","w+b");
  1606.     setbuf(Vimage_Save2,Vi_Inbuff2);
  1607. }
  1608.  
  1609. /* ******************************************************************
  1610. **    
  1611. **        sets input files for do_menu() etc.
  1612. **
  1613. ********************************************************************* */
  1614.         
  1615. void set_files()
  1616.  
  1617. {
  1618.     Vimage_Save1=fopen("image1.sav","w+b");
  1619.     setbuf(Vimage_Save1,Vi_Inbuff1);
  1620.     Vimage_Save2=fopen("image2.sav","w+b");
  1621.     setbuf(Vimage_Save2,Vi_Inbuff2);
  1622. }
  1623.  
  1624.  
  1625. /***********************************************************************
  1626. **
  1627. **
  1628. **
  1629. **
  1630. ************************************************************************/
  1631.  
  1632. int swap(a,b)
  1633.  
  1634. int *a,*b;
  1635.  
  1636. {
  1637.     int t;
  1638.  
  1639.     t=*a;
  1640.     *a=*b;
  1641.     *b=t;
  1642. }
  1643.  
  1644.  
  1645. /***********************************************************************
  1646. **
  1647. **
  1648. **
  1649. **
  1650. ************************************************************************/
  1651.  
  1652. int plotln(hue,x1,y1,x2,y2,val)
  1653.  
  1654. int hue,x1,y1,x2,y2,val;
  1655.  
  1656. {
  1657.     int d,dx,dy;
  1658.     int a_incr,b_incr,y_incr,x_incr;
  1659.     int x,y;
  1660.  
  1661.     dx=abs(x2-x1);
  1662.     dy=abs(y2-y1);
  1663.     if(dx>dy)
  1664.     {
  1665.         if(x1>x2)
  1666.         {
  1667.             swap(&x1,&x2);
  1668.             swap(&y1,&y2);
  1669.         }
  1670.         if(y2>y1)                        /* determine increment for y */
  1671.             y_incr=1;
  1672.         else
  1673.             y_incr=-1;
  1674.         dx=x2-x1;                        /* initialize constants */
  1675.         dy=abs(y2-y1);
  1676.         d=2*dy-dx;
  1677.         a_incr=2*(dy-dx);                /* initial x and y */
  1678.         b_incr=2*dy;
  1679.         x=x1;
  1680.         y=y1;
  1681.         plotpt(hue,x,y,val);            /* plot pixel */
  1682.         for(x=x1+1;x<=x2;x++)
  1683.         {
  1684.             if(d>=0)
  1685.             {
  1686.                 y+=y_incr;
  1687.                 d+=a_incr;
  1688.             }
  1689.             else
  1690.                 d+=b_incr;
  1691.             plotpt(hue,x,y,val);
  1692.         }
  1693.     }
  1694.     else
  1695.     {
  1696.         if(y1>y2)
  1697.         {
  1698.             swap(&x1,&x2);
  1699.             swap(&y1,&y2);
  1700.         }
  1701.         if(x2>x1)                        /* determine increment for y */
  1702.             x_incr=1;
  1703.         else
  1704.             x_incr=-1;
  1705.         dy=y2-y1;                        /* initialize constants */
  1706.         dx=abs(x2-x1);
  1707.         d=2*dx-dy;
  1708.         a_incr=2*(dx-dy);                /* initial x and y */
  1709.         b_incr=2*dx;
  1710.         x=x1;
  1711.         y=y1;
  1712.         plotpt(hue,x,y,val);            /* plot pixel */
  1713.         for(y=y1+1;y<=y2;y++)
  1714.         {
  1715.             if(d>=0)
  1716.             {
  1717.                 x+=x_incr;
  1718.                 d+=a_incr;
  1719.             }
  1720.             else
  1721.                 d+=b_incr;
  1722.             plotpt(hue,x,y,val);
  1723.         }
  1724.     }
  1725. }
  1726.  
  1727.  
  1728. /* ******************************************************************
  1729. **
  1730. **    draw a line on the image and save data destroyed in buffer
  1731. **
  1732. **    returns the number of points ploted
  1733. **
  1734. ********************************************************************* */
  1735.  
  1736. int tplotln_val(hue,x1,y1,x2,y2,buffer,val)
  1737.  
  1738. int hue;    /* image plane */
  1739. int x1,y1;    /* coordinates of 1st point */
  1740. int x2,y2;    /* coordinates of 2nd point */
  1741. unsigned char *buffer;
  1742. int val;
  1743.  
  1744. {
  1745.     int numpts=0;
  1746.     int d,dx,dy;
  1747.     int a_incr,b_incr,y_incr,x_incr;
  1748.     int x,y;
  1749.  
  1750.     dx=abs(x2-x1);
  1751.     dy=abs(y2-y1);
  1752.     if(dx>dy)
  1753.     {
  1754.         if(x1>x2)
  1755.         {
  1756.             swap(&x1,&x2);
  1757.             swap(&y1,&y2);
  1758.         }
  1759.         if(y2>y1)                        /* determine increment for y */
  1760.             y_incr=1;
  1761.         else
  1762.             y_incr=-1;
  1763.         dx=x2-x1;                        /* initialize constants */
  1764.         dy=abs(y2-y1);
  1765.         d=2*dy-dx;
  1766.         a_incr=2*(dy-dx);                /* initial x and y */
  1767.         b_incr=2*dy;
  1768.         x=x1;
  1769.         y=y1;
  1770.         if(x>=0&&x<ScreenXs&&y>=0&&y<ScreenYs)
  1771.         {
  1772.             *buffer++=getpt(hue,x,y);
  1773.             numpts+=1;
  1774.             plotpt(hue,x,y,val);            /* plot pixel */
  1775.         }
  1776.         for(x=x1+1;x<=x2;x++)
  1777.         {
  1778.             if(d>=0)
  1779.             {
  1780.                 y+=y_incr;
  1781.                 d+=a_incr;
  1782.             }
  1783.             else
  1784.                 d+=b_incr;
  1785.             if(x>=0&&x<ScreenXs&&y>=0&&y<ScreenYs)
  1786.             {
  1787.                 *buffer++=getpt(hue,x,y);
  1788.                 numpts+=1;
  1789.                 plotpt(hue,x,y,val);            /* plot pixel */
  1790.             }
  1791.         }
  1792.     }
  1793.     else
  1794.     {
  1795.         if(y1>y2)
  1796.         {
  1797.             swap(&x1,&x2);
  1798.             swap(&y1,&y2);
  1799.         }
  1800.         if(x2>x1)                        /* determine increment for y */
  1801.             x_incr=1;
  1802.         else
  1803.             x_incr=-1;
  1804.         dy=y2-y1;                        /* initialize constants */
  1805.         dx=abs(x2-x1);
  1806.         d=2*dx-dy;
  1807.         a_incr=2*(dx-dy);                /* initial x and y */
  1808.         b_incr=2*dx;
  1809.         x=x1;
  1810.         y=y1;
  1811.         if(x>=0&&x<ScreenXs&&y>=0&&y<ScreenYs)
  1812.         {
  1813.             *buffer++=getpt(hue,x,y);
  1814.             numpts+=1;
  1815.             plotpt(hue,x,y,val);            /* plot pixel */
  1816.         }
  1817.         for(y=y1+1;y<=y2;y++)
  1818.         {
  1819.             if(d>=0)
  1820.             {
  1821.                 x+=x_incr;
  1822.                 d+=a_incr;
  1823.             }
  1824.             else
  1825.                 d+=b_incr;
  1826.             if(x>=0&&x<ScreenXs&&y>=0&&y<ScreenYs)
  1827.             {
  1828.                 *buffer++=getpt(hue,x,y);
  1829.                 numpts+=1;
  1830.                 plotpt(hue,x,y,val);            /* plot pixel */
  1831.             }
  1832.         }
  1833.     }
  1834.     return(numpts);
  1835. }
  1836.  
  1837. /* ******************************************************************
  1838. **
  1839. **    draw a line on the image and save data destroyed in buffer
  1840. **
  1841. **    returns the number of points ploted
  1842. **
  1843. ********************************************************************* */
  1844.  
  1845. int tplotln_inv_dot(hue,x1,y1,x2,y2,buffer,dot)
  1846.  
  1847. int hue;    /* image plane */
  1848. int x1,y1;    /* coordinates of 1st point */
  1849. int x2,y2;    /* coordinates of 2nd point */
  1850. unsigned char *buffer;
  1851. int dot;
  1852.  
  1853. {
  1854.     int numpts=0;
  1855.     int d,dx,dy;
  1856.     int a_incr,b_incr,y_incr,x_incr;
  1857.     int x,y,val;
  1858.  
  1859.     dx=abs(x2-x1);
  1860.     dy=abs(y2-y1);
  1861.     if(dx>dy)
  1862.     {
  1863.         if(x1>x2)
  1864.         {
  1865.             swap(&x1,&x2);
  1866.             swap(&y1,&y2);
  1867.         }
  1868.         if(y2>y1)                        /* determine increment for y */
  1869.             y_incr=1;
  1870.         else
  1871.             y_incr=-1;
  1872.         dx=x2-x1;                        /* initialize constants */
  1873.         dy=abs(y2-y1);
  1874.         d=2*dy-dx;
  1875.         a_incr=2*(dy-dx);                /* initial x and y */
  1876.         b_incr=2*dy;
  1877.         x=x1;
  1878.         y=y1;
  1879.         if(x>=0&&x<ScreenXs&&y>=0&&y<ScreenXs)
  1880.         {
  1881.             *buffer++=val=getpt(hue,x,y);
  1882.             numpts+=1;
  1883.             if(val>128)
  1884.                 val==0;
  1885.             else
  1886.                 val=225;
  1887.             plotpt(hue,x,y,val);            /* plot pixel */
  1888.         }
  1889.         for(x=x1+1;x<=x2;x++)
  1890.         {
  1891.             if(d>=0)
  1892.             {
  1893.                 y+=y_incr;
  1894.                 d+=a_incr;
  1895.             }
  1896.             else
  1897.                 d+=b_incr;
  1898.             if(x>=0&&x<ScreenXs&&y>=0&&y<ScreenYs)
  1899.             {
  1900.                 *buffer++=val=getpt(hue,x,y);
  1901.                 numpts+=1;
  1902.                 if(val>128)
  1903.                     val==0;
  1904.                 else
  1905.                     val=225;
  1906.                 plotpt(hue,x,y,val);            /* plot pixel */
  1907.             }
  1908.         }
  1909.     }
  1910.     else
  1911.     {
  1912.         if(y1>y2)
  1913.         {
  1914.             swap(&x1,&x2);
  1915.             swap(&y1,&y2);
  1916.         }
  1917.         if(x2>x1)                        /* determine increment for y */
  1918.             x_incr=1;
  1919.         else
  1920.             x_incr=-1;
  1921.         dy=y2-y1;                        /* initialize constants */
  1922.         dx=abs(x2-x1);
  1923.         d=2*dx-dy;
  1924.         a_incr=2*(dx-dy);                /* initial x and y */
  1925.         b_incr=2*dx;
  1926.         x=x1;
  1927.         y=y1;
  1928.         if(x>=0&&x<ScreenXs&&y>=0&&y<ScreenYs)
  1929.         {
  1930.             *buffer++=val=getpt(hue,x,y);
  1931.             numpts+=1;
  1932.             if(val>128)
  1933.                 val==0;
  1934.             else
  1935.                 val=225;
  1936.             plotpt(hue,x,y,val);            /* plot pixel */
  1937.         }
  1938.         for(y=y1+1;y<=y2;y++)
  1939.         {
  1940.             if(d>=0)
  1941.             {
  1942.                 x+=x_incr;
  1943.                 d+=a_incr;
  1944.             }
  1945.             else
  1946.                 d+=b_incr;
  1947.             if(x>=0&&x<ScreenXs&&y>=0&&y<ScreenYs)
  1948.             {
  1949.                 *buffer++=val=getpt(hue,x,y);
  1950.                 numpts+=1;
  1951.                 if(val>128)
  1952.                     val==0;
  1953.                 else
  1954.                     val=225;
  1955.                 plotpt(hue,x,y,val);            /* plot pixel */
  1956.             }
  1957.         }
  1958.     }
  1959.     return(numpts);
  1960. }
  1961.  
  1962. /* ******************************************************************
  1963. **
  1964. **    removes a line drawn with tplot_val()
  1965. **
  1966. ********************************************************************* */
  1967.  
  1968. int unplotln(hue,x1,y1,x2,y2,buffer)
  1969.  
  1970. int hue;    /* image plane */
  1971. int x1,y1;    /* coordinates of 1st point */
  1972. int x2,y2;    /* coordinates of 2nd point */
  1973. unsigned char *buffer;
  1974.  
  1975. {
  1976.     int numpts=0;
  1977.     int d,dx,dy;
  1978.     int a_incr,b_incr,y_incr,x_incr;
  1979.     int x,y;
  1980.  
  1981.     dx=abs(x2-x1);
  1982.     dy=abs(y2-y1);
  1983.     if(dx>dy)
  1984.     {
  1985.         if(x1>x2)
  1986.         {
  1987.             swap(&x1,&x2);
  1988.             swap(&y1,&y2);
  1989.         }
  1990.         if(y2>y1)                        /* determine increment for y */
  1991.             y_incr=1;
  1992.         else
  1993.             y_incr=-1;
  1994.         dx=x2-x1;                        /* initialize constants */
  1995.         dy=abs(y2-y1);
  1996.         d=2*dy-dx;
  1997.         a_incr=2*(dy-dx);                /* initial x and y */
  1998.         b_incr=2*dy;
  1999.         x=x1;
  2000.         y=y1;
  2001.         if(x>=0&&x<ScreenXs&&y>=0&&y<ScreenYs)
  2002.             plotpt(hue,x,y,*buffer++);
  2003.         for(x=x1+1;x<=x2;x++)
  2004.         {
  2005.             if(d>=0)
  2006.             {
  2007.                 y+=y_incr;
  2008.                 d+=a_incr;
  2009.             }
  2010.             else
  2011.                 d+=b_incr;
  2012.             if(x>=0&&x<ScreenXs&&y>=0&&y<ScreenYs)
  2013.                 plotpt(hue,x,y,*buffer++);
  2014.         }
  2015.     }
  2016.     else
  2017.     {
  2018.         if(y1>y2)
  2019.         {
  2020.             swap(&x1,&x2);
  2021.             swap(&y1,&y2);
  2022.         }
  2023.         if(x2>x1)                        /* determine increment for y */
  2024.             x_incr=1;
  2025.         else
  2026.             x_incr=-1;
  2027.         dy=y2-y1;                        /* initialize constants */
  2028.         dx=abs(x2-x1);
  2029.         d=2*dx-dy;
  2030.         a_incr=2*(dx-dy);                /* initial x and y */
  2031.         b_incr=2*dx;
  2032.         x=x1;
  2033.         y=y1;
  2034.         if(x>=0&&x<ScreenXs&&y>=0&&y<ScreenYs)
  2035.             plotpt(hue,x,y,*buffer++);
  2036.         for(y=y1+1;y<=y2;y++)
  2037.         {
  2038.             if(d>=0)
  2039.             {
  2040.                 x+=x_incr;
  2041.                 d+=a_incr;
  2042.             }
  2043.             else
  2044.                 d+=b_incr;
  2045.             if(x>=0&&x<ScreenXs&&y>=0&&y<ScreenYs)
  2046.                 plotpt(hue,x,y,*buffer++);
  2047.         }
  2048.     }
  2049. }
  2050.  
  2051.  
  2052. /* ******************************************************************
  2053. **
  2054. **    draw a line on the image
  2055. **
  2056. ********************************************************************* */
  2057.  
  2058. int plotln_val(hue,x1,y1,x2,y2,high,low,center,first)
  2059.  
  2060. int hue;    /* image plane */
  2061. int x1,y1;    /* coordinates of 1st point */
  2062. int x2,y2;    /* coordinates of 2nd point */
  2063. int high,low,center;    /* brightness of line */
  2064. int first;
  2065.  
  2066. {
  2067.  
  2068.     int   i, j, k, numx, numy,val;
  2069.     float x, y, dy, dx;
  2070.  
  2071. /*    DrawVector(y1,x1,y2,x2,val);*/
  2072.  
  2073.     numx = ( x2 > x1 ) ? x2-x1 : x1-x2;
  2074.     numy = ( y2 > y1 ) ? y2-y1 : y1-y2;
  2075.     if(numx==0 && numy==0) return;
  2076.     if( numx>numy ) 
  2077.     {
  2078.         dy = (float)(y2-y1)/(float)(x2-x1);
  2079.         dx = (x2>x1) ? 1.0 : -1.0;
  2080.         i = x = x1;
  2081.         j = y = y1;
  2082.         for(k=0;k<=(numx);k++)
  2083.         {
  2084.             val=(getpt(0,i,j)<center)?low:high;
  2085.             if(k>=first)
  2086.                 plotpt(3,i,j,val);
  2087.             x += dx;
  2088.             y += dy*dx;
  2089.             if(dy>=0.0)
  2090.             {
  2091.                 i = x;
  2092.                 j = y;
  2093.             }
  2094.             else
  2095.             {
  2096.                 i = x;
  2097.                 j = y+0.5;
  2098.             }
  2099.         }
  2100.     }
  2101.     else{
  2102.         dx = (float)(x2-x1)/(float)(y2-y1);
  2103.         dy = (y2>y1) ? 1.0 : -1.0;
  2104.         i = x = x1;
  2105.         j = y = y1;
  2106.         for(k=0;k<=(numy);k++)
  2107.         {
  2108.             val=(getpt(0,i,j)<center)?low:high;
  2109.             if(k>=first)
  2110.                 plotpt(3,i,j,val);
  2111.             x += dx*dy;
  2112.             y += dy;
  2113.             if(dx>=0.0)
  2114.             {
  2115.                 i = x;
  2116.                 j = y;
  2117.             }
  2118.             else
  2119.             {
  2120.                 i = x+0.5;
  2121.                 j = y;
  2122.             }
  2123.         }
  2124.     }
  2125. }
  2126.  
  2127.  
  2128.  
  2129. /* ******************************************************************
  2130. **
  2131. **    draws a box of brightness 'val' at 'xc,yc' size 'size'
  2132. **
  2133. **    functions called: 
  2134. **        plotpt();
  2135. **
  2136. **
  2137. ********************************************************************* */
  2138.  
  2139. void box(hue,xc,yc,val,xsize,ysize)
  2140.  
  2141. int hue;    /* image plane */
  2142. int xc,yc;    /* coordinates of box upper left corner */
  2143. int val;    /* brightness of box */
  2144. int xsize,ysize;    /* length of sides */
  2145.  
  2146. {
  2147.     int i,j,k,y1,y2,x1,x2;
  2148.     
  2149.     y1 = yc;
  2150.     y2 = yc+ysize;
  2151.     x1 = xc;
  2152.     x2 = xc+xsize;
  2153.  
  2154.     for(i=y1;i<=y2;i++)
  2155.     {
  2156.         plotpt(3,x1,i,val);
  2157.         plotpt(3,x2,i,val);
  2158.     }
  2159.     for(i=x1;i<=x2;i++)
  2160.     {
  2161.         plotpt(3,i,y1,val);
  2162.         plotpt(3,i,y2,val);
  2163.     }
  2164. }
  2165.  
  2166.  
  2167. /* ******************************************************************
  2168. **
  2169. **    draws a cursor (usually hue = 3)
  2170. **
  2171. **    functions called:
  2172. **        plotpt();
  2173. **
  2174. ********************************************************************* */
  2175.  
  2176. void cursor(hue,x,y,val,size)
  2177.  
  2178. int hue;    /* image plane */
  2179. int x,y;    /* cursor center coordinates */
  2180. int val;    /* brightness of cursor */
  2181. int size;    /* length of arms */
  2182.  
  2183. {
  2184.     int i,j;
  2185.  
  2186.     for(i=y-size;i<=y+size;i++)
  2187.         if(i!=y)
  2188.             plotpt(hue,x,i,val);
  2189.     for(j=x-size;j<=x+size;j++)
  2190.         if(j!=x)
  2191.             plotpt(hue,j,y,val);
  2192. }
  2193.  
  2194. /* ******************************************************************
  2195. **
  2196. **    draws a cursor and puts points removed in buff
  2197. **
  2198. **    returns number of points removed
  2199. **
  2200. **    functions called:
  2201. **        plotpt();
  2202. **        getpt();
  2203. **
  2204. ********************************************************************* */
  2205.  
  2206. int tcursor(hue,x,y,size,buff)
  2207.  
  2208. int hue;    /* image plane */
  2209. int x,y;    /* cursor center coordinates */
  2210. int size;    /* length of arms */
  2211. unsigned char *buff;    /* points removed */
  2212.  
  2213. {
  2214.     int i,j,num=0,val;
  2215.  
  2216.     if(hue==3)
  2217.     {
  2218.         for(i=y-size;i<=y+size;i++)
  2219.             if(i>=0&&i<ScreenYs&&i!=y) 
  2220.             {
  2221.                 buff[num]=getpt(hue,x,i);
  2222.                 val=(buff[num++]%128>64)?16:255;
  2223.                 WritePixel(i,x,val);
  2224.             }
  2225.         for(j=x-size;j<=x+size;j++)
  2226.             if(j>=0&&j<ScreenXs&&j!=x) 
  2227.             {
  2228.                 buff[num]=getpt(hue,j,y);
  2229.                 val=(buff[num++]%128>64)?16:255;
  2230.                 WritePixel(y,j,val);
  2231.             }
  2232.     }
  2233.     else
  2234.     {
  2235.         for(i=y-size;i<=y+size;i++)
  2236.             if(i>=0&&i<ScreenYs&&i!=y) 
  2237.             {
  2238.                 buff[num]=getpt(hue,x,i);
  2239.                 val=(buff[num++]>128)?16:255;
  2240.                 WritePixel(i,x,val);
  2241.             }
  2242.         for(j=x-size;j<=x+size;j++)
  2243.             if(j>=0&&j<ScreenXs&&j!=x) 
  2244.             {
  2245.                 buff[num]=getpt(hue,j,y);
  2246.                 val=(buff[num++]>128)?16:255;
  2247.                 WritePixel(y,j,val);
  2248.             }
  2249.     }
  2250.     return(num);
  2251. }
  2252.  
  2253.  
  2254. /* ******************************************************************
  2255. **
  2256. **    draws a cursor and puts points removed in buff
  2257. **
  2258. **    returns number of points removed
  2259. **
  2260. **    functions called:
  2261. **        plotpt();
  2262. **        getpt();
  2263. **
  2264. ********************************************************************* */
  2265.  
  2266. int tcursor_val(hue,x,y,size,buff,low_color,high_color,center_val)
  2267.  
  2268. int hue;    /* image plane */
  2269. int x,y;    /* cursor center coordinates */
  2270. int size;    /* length of arms */
  2271. int low_color,high_color,center_val;
  2272. unsigned char *buff;    /* points removed */
  2273.  
  2274. {
  2275.     int i,j,num=0,val;
  2276.  
  2277.     for(i=y-size;i<=y+size;i++)
  2278.         if(i>=0&&i<ScreenYs&&i!=y) 
  2279.         {
  2280.             buff[num]=getpt(hue,x,i);
  2281.             val=(buff[num++]>center_val)?low_color:high_color;
  2282.             WritePixel(i,x,val);
  2283.         }
  2284.     for(j=x-size;j<=x+size;j++)
  2285.         if(j>=0&&j<ScreenXs&&j!=x) 
  2286.         {
  2287.             buff[num]=getpt(hue,j,y);
  2288.             val=(buff[num++]>center_val)?low_color:high_color;
  2289.             WritePixel(y,j,val);
  2290.         }
  2291.     return(num);
  2292. }
  2293.  
  2294. /* ******************************************************************
  2295. **
  2296. **    undraws a cursor using the points removed in buff
  2297. **
  2298. **    functions called:
  2299. **        plotpt();
  2300. **
  2301. ********************************************************************* */
  2302.  
  2303. void uncursor(hue,x,y,size,buff)
  2304.  
  2305. int hue;    /* image plane */
  2306. int x,y;    /* cursor center coordinates */
  2307. int size;    /* length of arms */
  2308. unsigned char *buff;    /* points removed */
  2309.  
  2310. {
  2311.     int i,j,num=0;
  2312.  
  2313.     for(i=y-size;i<=y+size;i++)
  2314.         if(i>=0&&i<ScreenYs&&i!=y) 
  2315.             WritePixel(i,x,*buff++);
  2316.     for(j=x-size;j<=x+size;j++)
  2317.         if(j>=0&&j<ScreenXs&&j!=x)
  2318.             WritePixel(y,j,*buff++);
  2319. }
  2320.  
  2321.  
  2322. /* ******************************************************************
  2323. **
  2324. **    fills in color plane 'hue'
  2325. **
  2326. **    functions called:
  2327. **        plotpt();
  2328. **        getpt();
  2329. **        printf();  requires --  <stdio.h>
  2330. **        scanf();                        <stdio.h>
  2331. **
  2332. ******************************************************************** */
  2333.  
  2334. int fillin(hue,minn,x1,x2,y1,y2)
  2335.  
  2336. int hue;    /* color plane -- 0-3 */
  2337. int minn;    /* minimum number of vlaues used to fill */
  2338. int x1,x2,y1,y2;    /* portion of image to fill */
  2339.  
  2340. {
  2341.  
  2342.     int num, sum, row, col, subrow, subcol;
  2343.     int val;
  2344.     int numfld; /* number filled in */
  2345.  
  2346.     char misng = 0;            /* missing data value */
  2347.     char minnbr;            /* min number of neighbors needed to compute */
  2348.  
  2349.     numfld = 0;
  2350.     num = 0;
  2351.  
  2352.     if( minn == 0 ) {
  2353. /*        printf("%s\n",
  2354.         "Give minimum number of neigbors to use for filling. ( recomend 5 )");*/
  2355.         scanf("%d",&minnbr);
  2356. /*        printf("\n%s%d\n","Using minimum neighbors = ",minnbr);*/
  2357.     }
  2358.     else {
  2359.         minnbr = minn;
  2360.     }    
  2361.  
  2362.     paint(3,0);
  2363.     for( row = y1; row <= y2; row++ ){
  2364.         for( col = x1; col <= x2; col++ ){
  2365.             val = getpt(hue,col,row);
  2366.             if( val == misng ){
  2367.                 num = 0;
  2368.                 sum = 0;
  2369.                 for( subrow = row-1; subrow <= row + 1; subrow++){
  2370.                     if( subrow >= y1 && subrow <= y2 ) {
  2371.                         for( subcol = col-1; subcol <= col + 1; subcol++){
  2372.                             if( subcol >= x1 && subcol <= x2 ) {
  2373.                                 val = getpt(hue,subcol,subrow);
  2374.                                 if( val != misng && (getpt(3,subcol,subrow)) != 255 ){
  2375.                                     num += 1;
  2376.                                     sum += val;
  2377.                                 }
  2378.                             }                
  2379.                         }
  2380.                     }
  2381.                 }
  2382.                 if( num >= minnbr ){
  2383.                     val = sum / num;
  2384.                     WritePixel(row,col,val);
  2385.                     WritePixel(row,col,255);
  2386.                     numfld += 1;
  2387.                 }
  2388.             }
  2389.         }
  2390.     }
  2391.     paint(3,0);
  2392.     return(numfld);
  2393. }    
  2394.  
  2395.  
  2396. /* ******************************************************************
  2397. **
  2398. **     paints color plane 'hue' with value 'val' 
  2399. **
  2400. **    functions called: -- none
  2401. **
  2402. **    returns: 1  = painted
  2403. **                -1 = illegal hue
  2404. **
  2405. ********************************************************************* */
  2406.  
  2407. int paint(hue,val)
  2408.  
  2409. int hue;    /* color plane -- 0-3 */
  2410. int val;    /* brighness of pixel 0-255 */
  2411.  
  2412. {
  2413.  
  2414.     char far *bankSelect = (char far *) BANK_SEL;
  2415.     unsigned i;                /* loop counter */
  2416.     int j;                    /* buffer counter */
  2417.     int far *dispBuff = (int far *) DISP_BUFF;
  2418.     int status;
  2419.  
  2420.     status = -1;
  2421.     if(hue<0 || hue>3) return(status);
  2422.     status = 1;
  2423.  
  2424.     val += val*256;
  2425.     for ( j = hue*4; j <= hue*4+3; j++ ) {
  2426.         *bankSelect = j;
  2427.         for ( i = 0; i < NWORDS; i++ ) {
  2428.             *dispBuff++ = val;
  2429.         }
  2430.     }
  2431.     return(status);
  2432. }
  2433.  
  2434.  
  2435. /* ******************************************************************
  2436. **
  2437. **    gets val at coordinates x and y with gun hue
  2438. **
  2439. **    functions called: -- none
  2440. **
  2441. ********************************************************************* */
  2442.  
  2443. unsigned char getpt(hue,x,y)
  2444.  
  2445. int hue;    /* color plane -- 0-3 */
  2446. int x,y;    /* pixel coordinates */
  2447.  
  2448. {
  2449.     int val;
  2450.     unsigned char cval;
  2451.  
  2452.     if(x<0||x>=ScreenXs||y<0||y>=ScreenYs)
  2453.         return(0);
  2454.     ReadPixel(y,x,&val);
  2455.     cval=val;
  2456.     return (cval);
  2457. }
  2458.  
  2459.  
  2460. /* ******************************************************************
  2461. **
  2462. **    define output file
  2463. **
  2464. **    functions called:
  2465. **        creat();  requires -- <sys\types.h> <sys\stat.h> <io.h>
  2466. **        printf();                <stdio.h>
  2467. **        scanf();                    <stdio.h>
  2468. **
  2469. ********************************************************************* */
  2470.  
  2471. int file_w(fnameout)
  2472.  
  2473. char fnameout[40];
  2474.  
  2475. {
  2476.     int fp;    /* file handle */
  2477. /*    printf("\n%s\n","Give name of output file.");*/
  2478.     scanf("%s",fnameout);
  2479.  
  2480.     fp = creat(fnameout,0777);
  2481.     return(fp);
  2482. }
  2483.  
  2484.  
  2485. /* ******************************************************************
  2486. **
  2487. **    define input file
  2488. **
  2489. **    functions called:
  2490. **        open();  requires -- <fcntl.h> <sys\type.h> <sys\stat.h> 
  2491. **                                    <io.h> <stdlib.h> <errno.h>
  2492. **        printf();                <stdio.h>
  2493. **        scanf();                    <stdio.h>
  2494. **
  2495. ********************************************************************* */
  2496.  
  2497. int file_r(fnamein)
  2498.  
  2499. char fnamein[40];
  2500.  
  2501. {
  2502.     int fp;        /* file handle */
  2503.  
  2504. /*    printf("\n%s\n","Give name of input file.");*/
  2505.     scanf("%s",fnamein);
  2506.  
  2507.     while( (fp = open(fnamein,O_RDONLY|O_BINARY)) == NULL) {
  2508.         if(errno == EACCES) {
  2509.             printf("Given path name is a directory; or an attempt was\n");
  2510.             printf("made to open a read-only file for writing; or a shar-\n ");
  2511.             printf("ing violation occured (the file's sharing mode does\n ");
  2512.             printf("not allow the specific operations; MS-DOS Version 3.0\n");
  2513.             printf("or later only.\n ");
  2514.         }
  2515.         if(errno == EEXIST) {
  2516.             printf("the O_CREAT and O_EXCL flags are specified \n");
  2517.             printf("but the named file already exists.\n ");
  2518.         }
  2519.         if(errno == EMFILE) {
  2520.             printf("No more file handles available (too many open\n ");
  2521.             printf("files)\n ");
  2522.         }
  2523.         if(errno == ENOENT) {
  2524.             printf("File or path name not found. \n");
  2525.         }
  2526.         printf("%s is not a valid file name.  Please try again.\n\n",fnamein);
  2527.         printf("\n%s\n","Give name of input file.");
  2528.         scanf("%s",fnamein);
  2529.     }
  2530.     return(fp);
  2531. }
  2532.  
  2533. /*********************************************************************
  2534. **
  2535. **    reads the number pad and changes values
  2536. **
  2537. ********************************************************************* */
  2538.  
  2539. char getpad(size,x,y,speed,menu)
  2540.  
  2541. int *size,*x,*y;
  2542. int *speed,menu;    /* menu = 1 -- menu else no menu */
  2543.  
  2544. {
  2545.     char ans,ans2;
  2546.     menu=0;
  2547.     
  2548.     ans=getch();
  2549.     if(ans==0)
  2550.     {
  2551.         ans2=getch();
  2552.         if(ans2==59)
  2553.             return(ans2);
  2554.         if(ans2==71||ans2==72||ans2==73)
  2555.             *y-=*speed;
  2556.         if(ans2==79||ans2==80||ans2==81)
  2557.             *y+=*speed;
  2558.         if(ans2==71||ans2==75||ans2==79)
  2559.             *x-=*speed;
  2560.         if(ans2==73||ans2==77||ans2==81)
  2561.             *x+=*speed;
  2562.         if(*x<0)
  2563.             *x=0;
  2564.         if(*x>=ScreenXs)
  2565.             *x=ScreenXs-1;
  2566.         if(*y<0)
  2567.             *y=0;
  2568.         if(*y>=ScreenYs)
  2569.             *y=ScreenYs-1;
  2570.     }
  2571.     if(ans=='+'&&*speed<ScreenYs/4)
  2572.         *speed*=2;
  2573.     if(ans=='-'&&*speed>1)
  2574.         *speed/=2;
  2575.     return(ans);
  2576. }
  2577.  
  2578.